package com.dragon.web.commons.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dragon.app.commons.dto.BankcardSaveDTO;
import com.dragon.app.commons.service.BankService;
import com.dragon.app.ykd.dto.BankCardInfosDTO;
import com.dragon.app.ykd.dto.BankCardLoanDTO;
import com.fintech.common.vo.FintechResult;

/**
 * 银行或者关于银行卡
 * @author ljs
 *
 */
@Controller
@RequestMapping("${platform.name.code}")
public class BankController {

	

	@Autowired
	private BankService bankService;
	
	
	
	/**
	 * 根据用户Id按照类型获取银行卡的信息<br>
	 * 0-放款卡,1-还款卡,2-信用卡
	 * 
	 * @param shortUrl
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bankCard/getBankCardList")
	public FintechResult getBankCardList(@RequestHeader String accessToken, @RequestHeader String idFintechUmUser,
			@RequestBody BankCardInfosDTO bankCardInfosDTO) {
		return bankService.getBankCardList(accessToken, idFintechUmUser, bankCardInfosDTO);
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "bankCard/bankBindList")
	public FintechResult getBankBindList(@RequestHeader String accessToken, @RequestHeader String idFintechUmUser,
			@RequestBody BankCardInfosDTO bankCardInfosDTO) {
		return bankService.getBankBindList(accessToken, idFintechUmUser, bankCardInfosDTO);
	}
	
	/**
	 * 接收用户填写的的宝付发送给客户的验证
	 * 去宝付那边获取这个卡跟这个商户号对应的协议号
	 * @param bankcardSaveDTO 
	 * @param accessToken
	 * @param idFintechUmUser
	 * @return
	 * @author shan
	 */
	@ResponseBody
	@RequestMapping(value = "bankCard/saveBankCardNew")
	public FintechResult saveBankCardNew(@RequestBody BankcardSaveDTO bankcardSaveDTO,
			@RequestHeader(required = false) String accessToken,
			@RequestHeader(required = false) String idFintechUmUser) {
		return bankService.saveBankCardNew(bankcardSaveDTO, accessToken, idFintechUmUser);
	}
	
	/**
	 * 设置放款卡 还款卡 type 1 还款卡 2 放款卡 id 放款卡的id
	 * 
	 * @param shortUrl
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bankCard/loan/{loanId}")
	public FintechResult bankCardLoan(@PathVariable String loanId, @RequestBody BankCardLoanDTO bankCardLoanDTO,
			@RequestHeader String accessToken, @RequestHeader String idFintechUmUser) {
		return bankService.bankCardLoan(loanId, bankCardLoanDTO, accessToken, idFintechUmUser);
	}
	
	
	/**
	 * 根据银行产品信息预绑卡接口发送验证码
	 * 
	 * @param bankcardSaveDTO
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bank/preBindCard")
	public FintechResult bankPreBindCard(@RequestBody BankcardSaveDTO bankcardSaveDTO, @RequestHeader(required=false) String accessToken, @RequestHeader(required=false) String idFintechUmUser) {
		return bankService.bankPreBindCard(bankcardSaveDTO, accessToken, idFintechUmUser);
	}
	
	
	
	/**
	 * 查询支持银行列表
	 * @param bankcardSaveDTO
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bank/sustainBankList")
	public FintechResult sustainBankList(@RequestHeader(required=false) String accessToken, @RequestHeader(required=false) String idFintechUmUser) {
		return bankService.sustainBankList(accessToken, idFintechUmUser);
	}
	
	/**
	 * 根据卡号获取卡BIN信息
	 * 
	 * @param bankCardNo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bank/queryBnakCardBin/{bankCardNo}")
	public FintechResult queryBnakCardBin(@PathVariable String bankCardNo) {
		return bankService.queryBnakCardBin(bankCardNo);
	}

	/**
	 * 查询绑定成功的银行卡列表 
	 * 优先展示当前渠道的银行卡，如果存在老渠道的也会查出，根据is_support字段区分当前渠道是否支持
	 * @param accessToken
	 * @param idFintechUmUser
	 * @param bankCardInfosDTO
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bank/queryBankList")
	public FintechResult queryBankList(@RequestHeader String accessToken, @RequestHeader String idFintechUmUser) {
		return bankService.queryBankList(accessToken, idFintechUmUser);
	}
	
	/**
	 * 设置默认卡
	 * @param accessToken
	 * @param idFintechUmUser
	 * @param bankCardLoanDTO
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bank/setDefaultCard")
	public FintechResult setDefaultCard(@RequestHeader String accessToken, @RequestHeader String idFintechUmUser, @RequestBody BankCardLoanDTO bankCardLoanDTO) {
		return bankService.setDefaultCard(accessToken, idFintechUmUser, bankCardLoanDTO);
	}
}
